package cn.trip.biz.service.impl;

import cn.itrip.beans.dto.Dto;
import cn.itrip.beans.vo.ItripLabelDicVO;
import cn.itrip.common.RedisUtil;
import cn.itrip.dao.ItripLabelDicMapper;
import cn.trip.biz.service.ItripHotelDicService;
import cn.trip.biz.service.ItripHotelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service("itripHotelDicService")
public class ItripHotelDicServiceImpl implements ItripHotelDicService {
    @Autowired
    private ItripLabelDicMapper itripLabelDicMapper;
    @Autowired
    private RedisUtil redisUtil;

    /**
     * 获取出游类型
     *
     * @param parentId
     * @return
     */
    @Override
    public Dto<List<ItripLabelDicVO>> selectTravelType(Long parentId) {
        Dto<List<ItripLabelDicVO>> dto = new Dto<>();
        String key = "labelDic:travelType:parentId=" + parentId;
        List<ItripLabelDicVO> itripLabelDicVOList;
        if (redisUtil.hasKey(key)) {
            itripLabelDicVOList = (List<ItripLabelDicVO>) redisUtil.get(key);
        } else {
            itripLabelDicVOList = itripLabelDicMapper.getTravelTypeByParentId(parentId);
        }
        if (itripLabelDicVOList != null) {
            redisUtil.set(key, itripLabelDicVOList, 600);
            dto.setSuccess("true");
            dto.setErrorCode("0");
            dto.setData(itripLabelDicVOList);
        } else {
            dto.setSuccess("false");
            dto.setMsg("没有旅游类型");
        }
        return dto;
    }


}
